package cn.stylefeng.guns.modular.business.app.controller;

import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.modular.business.app.controller.dto.CreatePayOrderDTO;
import cn.stylefeng.guns.modular.business.app.controller.dto.DocumentTypeCodeDTO;
import cn.stylefeng.guns.modular.business.app.controller.dto.GetPayStatusDTO;
import cn.stylefeng.guns.modular.business.app.controller.dto.ProvincialAndUrbanCodeDTO;
import cn.stylefeng.guns.modular.business.app.controller.req.BankCodeReq;
import cn.stylefeng.guns.modular.business.app.controller.vo.*;
import cn.stylefeng.guns.modular.business.app.service.ApiPayService;
import cn.stylefeng.guns.modular.business.app.service.DocumentTypeCodeService;
import cn.stylefeng.guns.modular.business.app.service.ProvincialAndUrbanCodeService;
import cn.stylefeng.guns.modular.business.frequency.orderfinish.model.param.OrderFinishRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 支付功能
 */
@CrossOrigin
@RestController
@RequestMapping("/api/pay")
public class ApiPayController {

    @Autowired
    private ApiPayService apiPayService;

    @Autowired
    private ProvincialAndUrbanCodeService codeService;

    @Autowired
    private DocumentTypeCodeService typeCodeService;


    /**
     * 企业用户基本信息开户获取省编码
     */
    @GetMapping("/getProvinceCode")
    public ResponseData<ProvincialAndUrbanCodeDTO> getProvinceCode() {
        return codeService.getProvinceCode();
    }

    /**
     * 企业用户基本信息开户获取市编码
     */
    @GetMapping("/getCityCode")
    public ResponseData<ProvincialAndUrbanCodeDTO> getCityCode(@Validated GetCityCodeVO getCityCodeVO) {
        return codeService.getCityCode(getCityCodeVO);
    }

    /**
     * 企业用户基本信息开户获取区编码
     */
    @GetMapping("/getAreaCode")
    public ResponseData<ProvincialAndUrbanCodeDTO> getAreaCode(@Validated GetAreaCodeVO getAreaCodeVO) {
        return codeService.getAreaCode(getAreaCodeVO);
    }

    /**
     * 获取证件类型编码
     */
    @GetMapping("/getDocumentTypeCode")
    public ResponseData<DocumentTypeCodeDTO> getDocumentTypeCode() {
        return typeCodeService.getDocumentTypeCode();
    }

    /**
     * 在网点代收页面完成支付
     */
    @PostMapping("/paymentOfSpecifiedAmount")
    public ResponseData<CreatePayOrderDTO> paymentOfSpecifiedAmount(@Validated @RequestBody PaymentOfSpecifiedAmountVO paymentOfSpecifiedAmountVO) {
        return apiPayService.paymentOfSpecifiedAmount(paymentOfSpecifiedAmountVO);
    }

    /**
     * 在待交付页面完成支付
     */
    @PostMapping("/payByOrder")
    public ResponseData<CreatePayOrderDTO> payByOrder(@Validated @RequestBody OrderFinishRecordVO orderFinishRecordVO) {
        return apiPayService.payByOrder(orderFinishRecordVO);
    }

    /**
     * 在修改订单页面完成现付-线上支付
     */
    @PostMapping("/payByUpdateOrder")
    public ResponseData<CreatePayOrderDTO> payByUpdateOrder(@Validated @RequestBody PayByUpdateOrderVO payByUpdateOrderVO) {
        return apiPayService.payByUpdateOrder(payByUpdateOrderVO);
    }

    /**
     * 完成欠付支付
     */
    @PostMapping("/payBackOrder")
    public ResponseData<CreatePayOrderDTO> payBackOrder(@Validated @RequestBody PayByUpdateOrderVO payByUpdateOrderVO) {
        return apiPayService.payBackOrder(payByUpdateOrderVO);
    }

    /**
     * 根据订单唯一标识查询订单支付状态
     */
    @PostMapping("/getPayStatus")
    public ResponseData<GetPayStatusDTO> getPayStatus(@Validated @RequestBody GetPayStatusVO getPayStatusVO) {
        return apiPayService.getPayStatus(getPayStatusVO);
    }

    /**
     * 在微信支付前生成一个唯一标识
     *
     * @return
     */
    @GetMapping("/getPayId")
    public ResponseData getPayId() {
        return apiPayService.getPayId();
    }

    /**
     * 根据订单唯一标识查询订单支付状态
     */
    @PostMapping("/getWxPayStatus")
    public ResponseData<GetPayStatusDTO> getWxPayStatus(@Validated @RequestBody GetWxPayStatusVO getWxPayStatusVO) {
        return apiPayService.getWxPayStatus(getWxPayStatusVO);
    }

    /**
     * 根据订单id查询订单支付状态
     */
    @PostMapping("/getPayStatusByOrderId")
    public ResponseData<GetPayStatusDTO> getPayStatusByOrderId(@Validated @RequestBody GetPayStatusByOrderIdVo getPayStatusByOrderIdVo) {
        return apiPayService.getPayStatusByOrderId(getPayStatusByOrderIdVo);
    }

    /**
     * 在创建订单生成支付宝或微信支付信息
     */
    @PostMapping("/getPayInfo")
    public ResponseData<CreatePayOrderDTO> getPayInfo(@RequestBody @Validated GetPayInfoVO getPayInfoVO) {
        return apiPayService.getPayInfo(getPayInfoVO);
    }

    /**
     * 获取省市编码信息
     */
    /*@GetMapping("/getProvinceAndCityCode")
    public ResponseData<String> getProvinceAndCityCode() {
        return apiPayService.getProvinceAndCityCode();
    }*/

    /**
     * 获取银行代码
     */
    @GetMapping("/getBankCode")
    public ResponseData<BankCodeReq> getBankCode() {
        return apiPayService.getBankCode();
    }

    /**
     * 获取openId
     */
    @GetMapping("/getOpenId")
    public ResponseData getOpenId(@RequestParam("code") String code) {
        return apiPayService.getOpenId(code);
    }
}
